<%--
    Document   : loanRequest
    Created on : 04 14, 11, 15:27:20 PM
    Author     : MonicaSandoval
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib  prefix="s" uri="/struts-tags" %>
<%@taglib  prefix="sj" uri="/struts-jquery-tags" %>
<%@taglib  prefix="sjg" uri="/struts-jquery-grid-tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<div id="preapproved" style="width: 100%">
    <s:url id="remoteurl" action="getackno" includeParams="all"/>
    <s:url id="loanappurl" value="loanprofile-loanapp.jsp" />
        <script type="text/javascript">
            var y = 0;
                $.subscribe("gridCompleteTopics",function() {
                var ids = document.getElementById("selected").value;
                jQuery.each(y,function(index, item) {
                    jQuery("#gridtable").jqGrid("setSelection", item);
                });
                jQuery.each(ids,function(index, item) {
                    var flag = false;
                    for(var prop in y){
                        if(item == y[prop]){
                            flag = true;
                        }
                    }
                
                if(!flag){
                    jQuery("#gridtable").jqGrid("setSelection", item);
                }                                   
            });
            y = document.getElementById("selected").value;
        });

        $.subscribe('getselectedids', function(event,data) {
            var s = $("#gridtable").jqGrid('getGridParam','selarrrow');
            document.getElementById("selected").value = s;
            check();
        });

        function check(){

            if(document.getElementById("selected").value.length != 0){
                while(document.getElementById("createReq").hasAttribute("style")){
                    document.getElementById("createReq").removeAttribute("style");
                }
                document.getElementById("createReq").style.fontSize = "12px";
                
            }else{
                document.getElementById("createReq").style.display = "none";
            }}
                        
            function proceedButton(){
                window.open("/Cashmate/acknowledgement.jsp?selected=" + document.getElementById("selected").value, "newWindow2");    
                location.reload(true);
            }
            function cancelButton(){
                $('#dialog').dialog('close');
            }

            function formatLink(cellvalue, options, rowObject) {
                return "<a href='<s:property value="loanappurl" />?id="+rowObject["loanverificationid"]+"' onClick='javascript: return openDialog(this)'>" + cellvalue + "</a>";
            }
            function openDialog(e) {
                window.open(e.href, "newWindow");
                return false;
            }
        </script>
    <sjg:grid
        id="gridtable"
        caption="Loans with Acknowledgement Receipts"
        dataType="json"
        href="%{remoteurl}"
        pager="true"
        autowidth="true"
        reloadTopics = "reloadItems"
        navigator="true"
        navigatorSearchOptions="{sopt:['eq']}"
        navigatorEdit="false"
        navigatorView="false"
        navigatorDelete="false"
        navigatorAdd="false"
        navigatorRefresh="true"
        gridModel="gridModel"
        rowList="10,15,20"
        rowNum="15"
        onCompleteTopics="gridCompleteTopics"
        onSelectRowTopics="getselectedids"

        >
        <sjg:gridColumn name="loanverificationid" index="loanverificationid" title="Loan Verification No." hidedlg="true" hidden="true" /> 
        <sjg:gridColumn name="loanid" index="loanid" title="Loan No." key="true" hidedlg="true" hidden="true" />        
        <sjg:gridColumn name="completename" index="name" title="Borrower Name" sortable="true" search="true" searchoptions="{sopt:['eq']}"/>
        <sjg:gridColumn name="loanamount" index="netloanableamount" title="Loan Amount" formatter="currency" align="right"/>
        <sjg:gridColumn name="netloanableamount" index="netloanableamount" title="Net Loanable Amount" formatter="currency" align="right"/>
        <sjg:gridColumn name="loanverification.areaname" index="area" title="Area" search="true" searchoptions="{sopt:['eq']}" align = "center" sortable="true"/>
        <sjg:gridColumn name="check.checkno" index="checkno" title="Check No." align = "center" />
        <sjg:gridColumn name="check.bankaccountno" index="bankaccountno" title="Bank Account No." align = "center" />
        <sjg:gridColumn name="dateapproved" index="date" title="Date Approved" align="center" search="true" searchoptions="{sopt:['eq']}" />
        <sjg:gridColumn name="loanverdocumentno" index="docno" title="Loan Application" formatter = "formatLink" align="center" cssClass="gridlink"/>
</sjg:grid>

    <br/>
    <hr/>
    <sj:dialog
        id="dialog"
        autoOpen="false"
        modal="true"
        buttons = "{
                'Proceed':function() { proceedButton(); },
                'Cancel':function() { cancelButton(); }
                }"
        title="Print Acknowledgement Receipt"        
        cssStyle="font-size:12px"
    >
        You are now about to print acknowledgement receipts.
        <s:form name="genreq" action="printackno" method="post" >
            <s:textfield name="selected" id="selected" value="" cssStyle="display:none" />
        </s:form>
    </sj:dialog>
    <sj:a
        name="createReq"
        id="createReq"
        openDialog="dialog"
        button="true"
        buttonIcon="ui-icon-print"
        cssStyle="display:none"
    >
        Release
    </sj:a>
</div>
